package cn.topevery.garden.dal.logic.event;

import cn.topevery.garden.dal.dao.event.EventDelayApplyDao;
import cn.topevery.garden.dal.dao.event.EventInfoDao;
import cn.topevery.garden.entity.dto.event.EventDelayApplyDTO;
import cn.topevery.garden.entity.po.event.EventDelayApply;
import cn.topevery.garden.entity.query.EventDelayApplyQuery;
import cn.topevery.garden.entity.vo.event.EventDelayApplyVO;
import cn.topevery.garden.framework.base.BaseLogic;
import hw.topevery.framework.DataFillHelper;
import hw.topevery.framework.db.base.BaseEntityDao;
import hw.topevery.framework.db.entity.DataPager;
import hw.topevery.framework.entity.KeyValue;
import hw.topevery.framework.web.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 案件延时申请表
 *
 * @author code-generate
 * @date 2020-12-01
 */
@Service
public class EventDelayApplyLogic extends BaseLogic<EventDelayApply> {
    @Autowired
    EventDelayApplyDao eventDelayApplyDao;

    @Autowired
    EventInfoDao eventInfoDao;

    @Override
    public BaseEntityDao<EventDelayApply, Integer> getDao() {
        return eventDelayApplyDao;
    }


    /**
     *  案件申请延时
     * @param dto
     * @return
     */
    public JsonResult<String> eventDelayApply(EventDelayApplyDTO dto) {
        boolean canApply = eventDelayApplyDao.canApply(dto.getEvtId());
        if (canApply) {
            EventDelayApply entity = new EventDelayApply();
            DataFillHelper.readToTarget(dto, entity);
            entity.isPass = 0;
            eventDelayApplyDao.insert(entity.reqUserId, entity);
            return JsonResult.ok("申请延时完成！");
        } else {
            return JsonResult.error("该案件已经申请延时,请勿重复申请！");
        }
    }

    public EventDelayApply getEntityByColumnEqValue(KeyValue<?> keyValue) {
        return eventDelayApplyDao.getEntityByColumnEqValue(keyValue);
    }

    public DataPager<EventDelayApplyVO> getEventDelayApplyList(EventDelayApplyQuery query) {
        return eventDelayApplyDao.getEventDelayApplyList(query);
    }
}
